package edu.hgnc.txTest;


import edu.hgnc.tx.annotation.config.TransactionConfig;
import edu.hgnc.tx.annotation.service.BookService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * 测试注解方式的声明事务
 */
public class JustTest2 {

	private static final Log logger = LogFactory.getLog(JustTest2.class);

	@Test
	public void test01() {
		logger.info("======================================================");
		logger.info("hello,when you see me,that's mean you are test succeed~");
		logger.info("======================================================");
	}
	@Test
	public void test02() {
		ArrayList<String> list = new ArrayList<>(Arrays.asList("1","2","3","4","5"));
		try {
			list.forEach(e->{
				if (e.equals("3")){
					throw new RuntimeException("遇到3就不执行");
				}
				System.out.println(e);
			});
			logger.debug("list=="+list);
		}catch (Exception e){
			logger.debug("中断原因==>"+e.getMessage());
		}
	}

	// 使用注解方式
	@Test
	public void test04() {
		logger.info("开始执行");
		if (logger.isDebugEnabled()){
			logger.debug("----------------------------------------------------------------------");

			AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
			context.register(TransactionConfig.class);
			context.refresh();
			BookService bookService = context.getBean("bookService", BookService.class);
			bookService.checkout("张三",1);
		}
	}


}
